package maze.utils;

import maze.contexts.MazeContext;
import maze.pojo.Action;
import maze.pojo.Point;

public class PointPool {
	private static final PointPool instance = new PointPool(MazeContext.width,
			MazeContext.height);
	
	private Point pool[][];
	
	public static PointPool getPool() {
		return instance;
	}

	private PointPool(int width, int height) {
		pool = new Point[width][height];
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				pool[x][y] = new Point(x, y);
			}
		}
	}

	public final Point get(int x, int y) {
		return pool[x][y];
	}

	public Point get(Point point) {
		return pool[point.x][point.y];
	}

	public final Point move(Point point, Action action) {
		switch (action) {
		case LEFT:
			return pool[point.x - 1][point.y];
		case RIGHT:
			return pool[point.x + 1][point.y];
		case UP:
			return pool[point.x][point.y - 1];
		case DOWN:
			return pool[point.x][point.y + 1];
		}
		return point;
	}
}
